package com.zg.scf.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.R;
import com.zg.scf.domain.req.StateReq;
import com.zg.scf.domain.req.product.ProductTypeAddReq;
import com.zg.scf.domain.req.product.ProductTypeEditReq;
import com.zg.scf.domain.req.product.ProductTypePageReq;
import com.zg.scf.domain.vo.ProductTypeVo;
import com.zg.scf.service.ProductTypeService;
import com.zg.scf.enm.StateEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * DESCRIPTION
 *
 * @author zhanfeng.liang
 * @since 2025-07-21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/scf/productType")
@Slf4j
@Api(tags = "产品类型")
public class ProductTypeController {

    private final ProductTypeService productTypeService;


    @PostMapping("/page")
    @ApiOperation(value = "分页")
    public R<Page<ProductTypeVo>> page(@RequestBody ProductTypePageReq pageReq) {
        Page<ProductTypeVo> page = productTypeService.page(pageReq,ProductTypeVo.class);
        return R.success(page);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public R add(@RequestBody @Valid ProductTypeAddReq addReq) {
        addReq.setState(StateEnum.N.getValue());
        productTypeService.add(addReq);
        return R.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改")
    public R edit(@RequestBody @Valid ProductTypeEditReq editReq) {
        productTypeService.edit(editReq);
        return R.success();
    }

    @PostMapping("/editState")
    @ApiOperation(value = "修改状态")
    public R editState(@RequestBody @Valid StateReq editReq) {
        productTypeService.editState(editReq);
        return R.success();
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    public R remove(@RequestBody List<Long> ids) {
        productTypeService.remove(ids);
        return R.success();
    }

}
